const logger = require("pomelo-logger").getLogger(__filename);
const HandlerUtil = require("../../../utils/handlerUtil");

module.exports = function (app) {
    return new Handler(app);
};

let Handler = function (app) {
    this.app = app;
};

Handler.prototype.getYuanBaoTables = function (msg, session, callback) {
    let service = this.app.get("zhuojiTableService");
    callback(null, HandlerUtil.getYuanBaoTables(service, msg.rid));
};

Handler.prototype.createYuanBaoTable = function (msg, session, callback) {
    let service = this.app.get("zhuojiTableService");
    HandlerUtil.createYuanBaoTable(this.app, service, msg, session, callback, function (msg) {
        let data = {};
        data["maxPlayers"] = 4;
        data["visible"] =  1;
        return data;
    });
};

Handler.prototype.leaveTable = function (msg, session, callback) {
    let service = this.app.get("zhuojiTableService");
    HandlerUtil.leaveTable(service, this.app, session, callback);
};

Handler.prototype.getReady = function (msg, session, callback) {
    let zhuojiTableService = this.app.get("zhuojiTableService");
    callback(null, zhuojiTableService.getReady(session.frontendId, session.id));
};

Handler.prototype.joinYuanBaoTable = function (msg, session, callback) {
    let service = this.app.get("zhuojiTableService");
    HandlerUtil.joinYuanBaoTable(this.app, service, msg, session, callback);
};

Handler.prototype.quickJoinYuanBaoTable = function (msg, session, callback) {
    let service = this.app.get("zhuojiTableService");
    HandlerUtil.quickJoinYuanBaoTable(this.app, service, msg, session, callback);
};

Handler.prototype.operate = function (msg, session, callback) {
    let zhuojiTableService = this.app.get("zhuojiTableService");
    zhuojiTableService.operate(session.frontendId, session.id, msg.operation, msg.card, callback);
};

Handler.prototype.tuoGuan = function (msg, session, callback) {
    let zhuojiTableService = this.app.get("zhuojiTableService");
    callback(null, zhuojiTableService.tuoGuan(session.frontendId, session.id, msg.auto));
};

Handler.prototype.tingBulb = function (msg, session, callback) {
    let zhuojiTableService = this.app.get("zhuojiTableService");
    callback(null, zhuojiTableService.tingBulb(session.frontendId, session.id));
};

Handler.prototype.notifyPlayers = function (msg, session, callback) {
    let zhuojiTableService = this.app.get("zhuojiTableService");
    callback(null, zhuojiTableService.sendChatMessage(session.frontendId, session.id, msg.message));
};
